import { useState, useEffect } from "react";
 type User= {
      id: string,
      firstName: string,
      lastName: string,
    };

const DataFetchingComponent = () => {
  const [data, setData] = useState<User | null>(null);

  useEffect(() => {
    fetch("https://api.example.com/user")
      .then((response) => {
        // console.log(response);
        return response.json();
      })
      .then((data) => setData(data))
      .catch((error) => console.error("Error:", error));
  }, []);

  return (
    <div>
      {/* {data ? <div>{JSON.stringify(data)}</div> : <div>Loading...</div>} */}
      {data ? <div>{`${data.id} ${data.firstName} ${data.lastName}`}</div> : <div>Loading...</div>}
    </div>
  );
};

export default DataFetchingComponent;
